#include "widget.h"
#include "ui_widget.h"

#ifdef Q_OS_WIN
#pragma comment(lib, "user32.lib")
#include <qt_windows.h>
#endif

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint | windowFlags());
    //WindowStaysOnTopHint 可以让窗体位于所有界面之上，类似于QQ主面板，一打开就在所有软件之上-比较霸道。
}

// 鼠标相对于窗体的位置 event->globalPos() - this->pos()
void Widget::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        m_bPressed = true;
        m_point = event->pos();
    }
}

// 若鼠标左键被按下，移动窗体位置
void Widget::mouseMoveEvent(QMouseEvent *event)
{
//    if (m_bPressed)
//        move(event->pos() - m_point + pos());

#ifdef Q_OS_WIN
    if (ReleaseCapture())
           SendMessage(HWND(winId()), WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
       event->ignore();
#else
#endif

}

// 设置鼠标未被按下
void Widget::mouseReleaseEvent(QMouseEvent *event)
{
    Q_UNUSED(event);

    m_bPressed = false;
}

Widget::~Widget()
{
    delete ui;
}
